package com.updateImage;

import net.coobird.thumbnailator.Thumbnails;
import net.coobird.thumbnailator.geometry.Coordinate;
import net.coobird.thumbnailator.geometry.Positions;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class test {
    public static void main(String[] args){
//        Thumbnails.of("images/test.jpg").size(1280, 1024).watermark(Positions.BOTTOM_RIGHT, ImageIO.read(new File("images/watermark.png")), 1f)
//                .outputQuality(1f).toFile("C:/image_watermark_bottom_right.jpg");
        //框架图文件路径

        String kuangjiaPath = "D:\\图片素材\\Fecheiws Store\\kuangjia";
        String ui1 = "D:\\图片素材\\第二家店铺图片\\主图修改\\ui图\\1.png";
        String ui2 = "D:\\图片素材\\第二家店铺图片\\主图修改\\ui图\\2.png";
        String ui3 = "D:\\图片素材\\第二家店铺图片\\主图修改\\ui图\\3.png";
        File file = new File(kuangjiaPath);
        File[] files = file.listFiles();
        for (int i = 1; i < 2; i++) {
            File file1 = files[i];
            String fileName = file1.getName();
            String[] splitStrings = fileName.split("_");
            String fileNameStr = splitStrings[0];
            String x1 = splitStrings[1];
            String y1 = splitStrings[2];
            String x2 = splitStrings[3];
            String y2 = splitStrings[4];
            String kuangjiaPath1 = kuangjiaPath+"\\"+fileName;
            File kuangjiaFile = new File(kuangjiaPath1);
            try {
                BufferedImage img = ImageIO.read(kuangjiaFile);
                int width = img.getWidth();
                int height = img.getHeight();
                BufferedImage uiImage1 = Thumbnails.of(ui1).size(Integer.parseInt(x2)-Integer.parseInt(x1), Integer.parseInt(y2)-Integer.parseInt(y1)).asBufferedImage( );
                Thumbnails.of(kuangjiaPath1).size(width,height)
                        .watermark(new Coordinate(Integer.parseInt(x1), Integer.parseInt(y1)),uiImage1,1f).toFile("D:\\图片素材\\第二家店铺图片\\主图修改\\结果\\1.png");

                BufferedImage uiImage2 = Thumbnails.of(ui2).size(Integer.parseInt(x2)-Integer.parseInt(x1), Integer.parseInt(y2)-Integer.parseInt(y1)).asBufferedImage( );
                Thumbnails.of(kuangjiaPath1).size(width,height)
                        .watermark(new Coordinate(Integer.parseInt(x1), Integer.parseInt(y1)),uiImage2,1f).toFile("D:\\图片素材\\第二家店铺图片\\主图修改\\结果\\2.png");

                BufferedImage uiImage3 = Thumbnails.of(ui3).size(Integer.parseInt(x2)-Integer.parseInt(x1), Integer.parseInt(y2)-Integer.parseInt(y1)).asBufferedImage( );
                Thumbnails.of(kuangjiaPath1).size(width,height)
                        .watermark(new Coordinate(Integer.parseInt(x1), Integer.parseInt(y1)),uiImage3,1f).toFile("D:\\图片素材\\第二家店铺图片\\主图修改\\结果\\3.png");
            } catch (IOException e) {
                e.printStackTrace();
            }


        }
    }
}
